/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.entity;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author GiangLT
 */
@Entity
@Table(name = "SERVICE_CONFIG", catalog = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ServiceConfig.findAll", query = "SELECT s FROM ServiceConfig s ORDER BY s.serviceName"),
    @NamedQuery(name = "ServiceConfig.findByServiceId", query = "SELECT s FROM ServiceConfig s WHERE s.serviceId = :serviceId"),
    @NamedQuery(name = "ServiceConfig.findByServiceName", query = "SELECT s FROM ServiceConfig s WHERE s.serviceName = :serviceName and s.startEffect >= :startEffect and s.endEffect <= :endEffect ORDER BY s.startEffect DESC"),
    @NamedQuery(name = "ServiceConfig.findGeneralServices", query = "SELECT s FROM ServiceConfig s WHERE s.serviceName NOT IN (:serviceNames)"),
    @NamedQuery(name = "ServiceConfig.findByCpNumber", query = "SELECT s FROM ServiceConfig s WHERE s.cpNumber = :cpNumber"),
    @NamedQuery(name = "ServiceConfig.findByStartEffect", query = "SELECT s FROM ServiceConfig s WHERE s.startEffect = :startEffect"),
    @NamedQuery(name = "ServiceConfig.findByEndEffect", query = "SELECT s FROM ServiceConfig s WHERE s.endEffect = :endEffect"),
    @NamedQuery(name = "ServiceConfig.findByContent", query = "SELECT s FROM ServiceConfig s WHERE s.content = :content"),
    @NamedQuery(name = "ServiceConfig.findByParam", query = "SELECT s FROM ServiceConfig s WHERE s.param = :param"),
    @NamedQuery(name = "ServiceConfig.findByDeliverContent", query = "SELECT s FROM ServiceConfig s WHERE s.deliverContent = :deliverContent")})
public class ServiceConfig implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "SERVICE_ID")
    private Long serviceId;
    @Size(max = 100)
    @Column(name = "SERVICE_NAME")
    private String serviceName;
    @Size(max = 20)
    @Column(name = "CP_NUMBER")
    private String cpNumber;
    @Column(name = "START_EFFECT")
    @Temporal(TemporalType.TIMESTAMP)
    private Date startEffect;
    @Column(name = "END_EFFECT")
    @Temporal(TemporalType.TIMESTAMP)
    private Date endEffect;
    @Size(max = 1000)
    @Column(name = "CONTENT")
    private String content;
    @Size(max = 400)
    @Column(name = "PARAM")
    private String param;
    @Size(max = 400)
    @Column(name = "DELIVER_CONTENT")
    private String deliverContent;
//    chuẩn bị cho phân chia dịch vụ
//    @Size(max = 400)
//    @Column(name = "GENERAL1")
//    private String general1;
//    @Size(max = 400)
//    @Column(name = "GENERAL2")
//    private String general2;
//    @Size(max = 400)
//    @Column(name = "GENERAL3")
//    private String general3;
//    @Size(max = 400)
//    @Column(name = "GENERAL4")
//    private String general4;
//    @Size(max = 400)
//    @Column(name = "GENERAL5")
//    private String general5;

    public ServiceConfig() {
    }

    public ServiceConfig(Long serviceId) {
        this.serviceId = serviceId;
    }

    public Long getServiceId() {
        return serviceId;
    }

    public void setServiceId(Long serviceId) {
        this.serviceId = serviceId;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public String getCpNumber() {
        return cpNumber;
    }

    public void setCpNumber(String cpNumber) {
        this.cpNumber = cpNumber;
    }

    public Date getStartEffect() {
        return startEffect;
    }

    public void setStartEffect(Date startEffect) {
        this.startEffect = startEffect;
    }

    public Date getEndEffect() {
        return endEffect;
    }

    public void setEndEffect(Date endEffect) {
        this.endEffect = endEffect;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        this.param = param;
    }

    public String getDeliverContent() {
        return deliverContent;
    }

    public void setDeliverContent(String deliverContent) {
        this.deliverContent = deliverContent;
    }
//    chuẩn bị cho phân chia dịch vụ
//    public String getGeneral1() {
//        return general1;
//    }
//
//    public void setGeneral1(String general1) {
//        this.general1 = general1;
//    }
//
//    public String getGeneral2() {
//        return general2;
//    }
//
//    public void setGeneral2(String general2) {
//        this.general2 = general2;
//    }
//
//    public String getGeneral3() {
//        return general3;
//    }
//
//    public void setGeneral3(String general3) {
//        this.general3 = general3;
//    }
//
//    public String getGeneral4() {
//        return general4;
//    }
//
//    public void setGeneral4(String general4) {
//        this.general4 = general4;
//    }
//
//    public String getGeneral5() {
//        return general5;
//    }
//
//    public void setGeneral5(String general5) {
//        this.general5 = general5;
//    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (serviceId != null ? serviceId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ServiceConfig)) {
            return false;
        }
        ServiceConfig other = (ServiceConfig) object;
        if ((this.serviceId == null && other.serviceId != null) || (this.serviceId != null && !this.serviceId.equals(other.serviceId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        result.append("ServiceConfig[");
        result.append("serviceId=").append(serviceId).append(" | ");
        result.append("serviceName=").append(serviceName).append(" | ");
        result.append("cpNumber=").append(cpNumber).append(" | ");
        result.append("startEffect=").append(dateFormat.format(startEffect)).append(" | ");
        result.append("endEffect=").append(dateFormat.format(endEffect)).append(" | ");
        result.append("param=").append(param).append(" | ");
//    chuẩn bị cho phân chia dịch vụ
//        result.append("user=").append(general1).append(" | ");
        result.append("content=").append(content).append(" | ");
        result.append("deliverContent=").append(deliverContent).append(" | ");
        result.append("]");
        return result.toString();
    }
    
}
